<?php 
    $dia=date("d/m/Y", time());
    $ahora=date("H:i", time());
?>

<div class="form">
    <script languaje="javascript">
        function reset(){
            document.getElementById("Comanda_data").value="<?php echo $dia ?>";
            document.getElementById("Comanda_hora").value="<?php echo $ahora ?>";            
        }

    </script>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'comanda-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Els camps amb <span class="required">*</span> són obligatoris.</p>

	<?php echo $form->errorSummary($model); ?>

    <?php
     
     if (Yii::app()->user->getState('rol')!='admin'){
         $lockerD=array('value'=>$dia,'readonly'=>'readonly','onChange'=>'reset();');
         $lockerH=array('value'=>$ahora,'readonly'=>'readonly','onChange'=>'reset();');
     }else{
         $lockerD=array('value'=>$dia);
         $lockerH=array('value'=>$ahora);
     }   
    ?>
    
    <div class="row">
        <?php echo $form->labelEx($model,'data'); ?>
        <?php            
            $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model'=>$model,
            'language'=>'ca',
            'attribute'=>'data',
            'value'=>$model->data,
            // additional javascript options for the date picker plugin
            'options'=>array(
                'showAnim'=>'fold',
                //'showButtonPanel'=>true,
                'autoSize'=>true,
                'dateFormat'=>'dd/mm/yy',
                'defaultDate'=>$model->data,
                'selectOtherMonths'=>true,
                'showOtherMonths'=>true,
                'changeMonth'=>'true',
                'changeYear'=>'true,'
            ),
            'htmlOptions'=>$lockerD
        ));
        ?>
        <?php echo $form->error($model,'data'); ?>
    </div>
    
    <br/>
    
    <div class="row">
	    <?php echo $form->labelEx($model,'hora'); ?>
	    <?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
            $this->widget('CJuiDateTimePicker',array(
                'model'=>$model, //Model object
                'attribute'=>'hora', //attribute name
                'mode'=>'time', //use "time","date" or "datetime" (default)
                'options'=>array(
                    'buttonImage'=>Yii::app()->baseUrl.'/images/icons/calendari.png',
                    'buttonImageOnly'=>true,
                ),
                'htmlOptions'=>$lockerH
            ));
        ?>
        <?php echo $form->error($model,'hora'); ?>
    </div>
    
    <br/>
    
    <div class="row">
		<?php 
        if (Yii::app()->user->getState('rol')=='servei') {
            echo $form->label($model,'persona_id').": ";
            echo Persona::model()->findbyPk(Yii::app()->user->id)->nom_real;
        }
        else {
            echo $form->labelEx($model,'persona_id');
            echo $form->dropDownList($model, 'persona_id',
            CHtml::listData(Persona::model()->findAll(), 'id', 'nom_real'),
                array('prompt'=>'(Tria un responsable)'));
            echo $form->error($model,'persona_id'); 
        }
        ?>
	</div>
    
    <br/>
    
    <div class="row">
		<?php echo $form->labelEx($model,'taula_id'); ?>
        <?php echo $form->dropDownList($model, 'taula_id',
            CHtml::listData(Taula::model()->findAll(), 'id', 'situacio'),
                array('prompt'=>'(Tria una taula)'));?>
        <?php echo $form->error($model,'taula_id'); ?>
	</div>
    
    <br/>
    
    <div class="row">
		<?php echo $form->labelEx($model,'estat_id'); ?>
        <?php echo $form->dropDownList($model, 'estat_id',
            CHtml::listData(Estat::model()->findAll(), 'id', 'nom_estat'),
                array('prompt'=>'(Tria un estat)'));?>
        <?php echo $form->error($model,'estat_id'); ?>
	</div>

    <br/>
    
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Crear' : 'Guardar'); ?>
	</div>

    <br/>
    
<?php $this->endWidget(); ?>

</div><!-- form -->